Socket
Socket
Sign inDemoInstall

p-pipe

Package Overview
Dependencies
0
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    p-pipe

Compose promise-returning & async functions into a reusable pipeline


Version published
Weekly downloads
2M
increased by0.01%
Maintainers
1
Created
Weekly downloads
 

Package description

What is p-pipe?

The p-pipe npm package allows you to compose promise-returning & async functions into a pipeline. It is useful for creating a sequence of asynchronous operations where the output of one function is passed as the input to the next.

What are p-pipe's main functionalities?

Basic Pipeline

This feature allows you to create a basic pipeline of asynchronous functions. In this example, the `add` function increments the input by 1, and the `multiply` function doubles the result. The pipeline processes the input `5` to produce the output `12`.

const pPipe = require('p-pipe');

const add = async x => x + 1;
const multiply = async x => x * 2;

const pipeline = pPipe(add, multiply);

pipeline(5).then(result => console.log(result)); // 12

Error Handling

This feature demonstrates how p-pipe handles errors in the pipeline. If any function in the pipeline throws an error, the pipeline will stop executing and return the error. In this example, the `throwError` function throws an error, which is caught and logged.

const pPipe = require('p-pipe');

const add = async x => x + 1;
const throwError = async x => { throw new Error('Something went wrong'); };
const multiply = async x => x * 2;

const pipeline = pPipe(add, throwError, multiply);

pipeline(5).catch(error => console.error(error.message)); // 'Something went wrong'

Synchronous Functions

This feature shows that p-pipe can also handle synchronous functions. The pipeline processes the input `5` to produce the output `12`, similar to the asynchronous example.

const pPipe = require('p-pipe');

const add = x => x + 1;
const multiply = x => x * 2;

const pipeline = pPipe(add, multiply);

pipeline(5).then(result => console.log(result)); // 12

Other packages similar to p-pipe

Readme

Source

p-pipe

Compose promise-returning & async functions into a reusable pipeline

Install

$ npm install p-pipe

Usage

import pPipe from 'p-pipe';

const addUnicorn = async string => `${string} Unicorn`;
const addRainbow = async string => `${string} Rainbow`;

const pipeline = pPipe(addUnicorn, addRainbow);

console.log(await pipeline('❤️'));
//=> '❤️ Unicorn Rainbow'

API

pPipe(input…)

The input functions are applied from left to right.

input

Type: Function

Expected to return a Promise or any value.

  • p-each-series - Iterate over promises serially
  • p-series - Run promise-returning & async functions in series
  • p-waterfall - Run promise-returning & async functions in series, each passing its result to the next
  • More…

Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.

Keywords

FAQs

Last updated on 08 Apr 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc